<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
	Object obj = request.getSession().getAttribute("role_resource");
	if (null == obj) {
		response.setStatus(1000);
		return;
	}
%>

<script type="text/javascript">
	
	//模板状态下拉列表
	var state_store = new Ext.data.JsonStore({
		fields : [ "id", "text" ],
		data : [ {
			id : "0",
			text : "退回"
		}, {
			id : "1",
			text : "启用"
		}, {
			id : "2",
			text : "草稿"
		} ]
	});
	//模板状态下拉列表
	var state_store1 = new Ext.data.JsonStore({
		fields : [ "id", "text" ],
		data : [ {
			id : "",
			text : "全部"
		}, {
			id : "0",
			text : "退回"
		}, {
			id : "1",
			text : "启用"
		}, {
			id : "2",
			text : "草稿"
		} ]
	});
	//账单类型下拉列表
	var type_store = new Ext.data.JsonStore({
		fields : [ "id", "text" ],
		data : [ {
			id : "1",
			text : "纸质"
		}, {
			id : "2",
			text : "电子"
		} ]
	});
	var type_store1 = new Ext.data.JsonStore({
		fields : [ "id", "text" ],
		data : [ {
			id : "",
			text : "全部"
		},{
			id : "1",
			text : "纸质"
		}, {
			id : "2",
			text : "电子"
		} ]
	});

	//卡产品树数据源
	var tree_store = new Ext.data.JsonStore({
		root : "data",
		fields : [ "id", "text", "leaf" ],
		url : "product!ProdType.action"
	});
	//模板列表数据源
	var data_store = new Ext.data.JsonStore({
		root : "data",
		totalProperty : "total",
		fields : [ "id", "name", "version", "cardid", "cardname", "type",
				"storpath", "jobpath", "images", "state", "personid",
				"createtime", "images" ],
		url : "template!NotVerifyList.action"
	});
	//模板从表数据源
	var sub_store = new Ext.data.JsonStore({
		root : "data",
		totalProperty : "total",
		fields : [ "stencil_no", "version", "in_no", "in_name" ],
		url : "template!listTemplateSub.action"
	});
	//模板版本号数据源
	var version_store = new Ext.data.JsonStore({
		root : "data",
		fields : [ "version" ],
		url : "template!selectVersion.action"
	});
	//模板id数据源
	var tempid_store = new Ext.data.JsonStore({
		root : "data",
		fields : [ "id" ],
		url : "template!DoTempid.action"
	});
	//编辑框record	
	var sub_record = Ext.data.Record.create([ "in_no", "in_name" ]);
	//图片路径,上传
	var image_store = new Ext.data.JsonStore({
		root : "data",
		fields : [ "path" ],
		url : "template!queryImage.action"
	});
	//样张框 record
	var image_record = Ext.data.Record.create([ "path" ]);
	//样张路径
	var img_path = function(e) {
		var record = Ext.getCmp("edit_grid").getSelectionModel().getSelected();
		if (record) {
			sub_store.remove(record);
			//Ext.Msg.alert("提示", "操作成功!");
			Ext.Msg.show({
		   		title:"提示",
		   		msg:"操作成功!",
		   		buttons:Ext.Msg.OK,
		   		icon: Ext.MessageBox.INFO
				});
		} else {
			//Ext.Msg.alert("错误", "未选中任何行信息,无法执行此操作!");
			Ext.Msg.show({
		   			title:"警告",
		  			msg: "未选中任何行信息,无法执行此操作!",
		   			buttons: Ext.Msg.OK,
		   			animEl: "elId",
		   			icon:Ext.MessageBox.WARNING
					});
			return;
		}
	};

	//定义数据显示面板
	var p1 = {
		id : "p1",
		xtype: "grid",
		stripeRows:true,
		loadMask : true,//在加载数据时遮罩住元素,替换元素Updater的加载提示器，并且在初始化加载之后销毁
		autoExpandColumn:"storpath",//自动填充
		autoExpandMin : 100,//自动填充最小宽度
		store : data_store,
		headersDisabled: true,
		columns : [ new Ext.grid.RowNumberer({
			header : "序号",
			width : 35,
			menuDisabled: true
		}), {
			header : "模板编号",
			dataIndex : "id",
			menuDisabled: true
		}, {
			header : "名称",
			dataIndex : "name",
			menuDisabled: true
		}, {
			header : "版本",
			dataIndex : "version",
			menuDisabled: true
		}, {
			header : "卡产品",
			dataIndex : "cardname",
			menuDisabled: true
		}, {
			header : "类型",
			dataIndex : "type",
			menuDisabled: true,
			renderer : function(input) {
				if ("1" == input)
					return "纸质";
				else if ("2" == input)
					return "电子";
			}
		}, {
			header : "存储路径",
			dataIndex : "storpath",
			id : "storpath",
			menuDisabled: true
		}, {
			header : "状态",
			dataIndex : "state",
			menuDisabled: true,
			renderer : function(input) {
				if ("0" == input)
					return "退回";
				else if ("1" == input)
					return "启用";
				else if ("2" == input)
					return "草稿";
				else if ("3" == input)
					return "审核中";
			}
		}, {
			header : "创建人",
			dataIndex : "personid",
			menuDisabled: true
		}, {
			header : "创建时间",
			dataIndex : "createtime",
			menuDisabled: true
		} ],
		buttonAlign : "center",
		bbar : new Ext.ux.PagingToolbar({
			id : "review",
			pageSize : limit,
			store : data_store
		}),
		buttons : [
				{
					text : "查看详情",
					id : "edit_tem",
					handler : function() {
						var p1 = this.ownerCt.ownerCt;
						var panel = p1.ownerCt;
						var record = p1.getSelectionModel().getSelected();
						if (record) {
							panel.getComponent("p2").setParam(record.data);
							oper_type = "upd";
							sub_store.load({
								params : {
									"templateSub.stencil_no" : record.data.id
								}
							});
							image_store.load({
								params : {
									"template.id" : record.data.id
								}
							});
							panel.layout.setActiveItem(1);
						} else {
							//Ext.Msg.alert("错误", "未选中任何行信息,无法进行此操作!");
							Ext.Msg.show({
		   							title:"警告",
		   							msg: "未选中任何行信息,无法进行此操作!",
		   							buttons: Ext.Msg.OK,
		   							animEl: "elId",
		   							icon:Ext.MessageBox.WARNING
							});
						}
					}
				} ],
		//查询条件
		tbar : ["&nbsp&nbsp账单类型:",
				{
					xtype : "billCombox",
					width : 120,
					store : type_store1,
					text : "查询条件",
					id : "selcbut",
					listeners : {
						"select" : function(comb, rcord, index) {
							var node = Ext.getCmp("tempTree")
									.getSelectionModel().getSelectedNode();
							if (node) {
								if (node.isLeaf()) {
									data_store.baseParams["template.type"] = rcord.data.id;
									data_store.load({
										params : {
											start : 0,
											limit : limit
										}
									});
								}
							} else {
								//Ext.Msg.alert("提示", "未选中任何行卡产品信息,无法执行此操作!");
								Ext.Msg.show({
		   							title:"警告",
		   							msg: "未选中任何行信息,无法进行此操作!",
		   							buttons: Ext.Msg.OK,
		   							animEl: "elId",
		   							icon:Ext.MessageBox.WARNING
							});
							}
						}
					}
				},"&nbsp&nbsp状态:",
					  {
						xtype : "billCombox",
						width : 120,
						store : state_store1,
						id : "selcstatebut",
						listeners : {
							"select" : function(comb, rcord, index) {
								var node = Ext.getCmp("tempTree").getSelectionModel().getSelectedNode();
								if (node) {
									if (node.isLeaf()) {
										data_store.baseParams["template.state"] = rcord.data.id;
										data_store.load({
											params : {
												start : 0,
												limit : limit
											}
										});
									}
								} else {
									//Ext.Msg.alert("提示", "未选中任何行卡产品信息,无法执行此操作!");
									Ext.Msg.show({
			   							title:"警告",
			   							msg: "未选中任何行信息,无法进行此操作!",
			   							buttons: Ext.Msg.OK,
			   							animEl: "elId",
			   							icon:Ext.MessageBox.WARNING
								});
								}
							}
						}
				},"&nbsp&nbsp模板名称",
					  {
						xtype : "textfield",
						id : "selcsnamebut",
						enableKeyEvents:true,
						listeners : {
							keypress:function(t,e){
								 if(13==e.getKey()){
									var node = Ext.getCmp("tempTree").getSelectionModel().getSelectedNode();
									if (node) {
										if (node.isLeaf()) {
											data_store.baseParams["template.name"] = t.getValue();
											data_store.load({
												params : {
													start : 0,
													limit : limit
												}
											});
										}
									} else {
										//Ext.Msg.alert("提示", "未选中任何行卡产品信息,无法执行此操作!");
										Ext.Msg.show({
				   							title:"警告",
				   							msg: "未选中任何行信息,无法进行此操作!",
				   							buttons: Ext.Msg.OK,
				   							animEl: "elId",
				   							icon:Ext.MessageBox.WARNING
									});
									}
								 }
							}
						}
				}  ]
	};

	var p4 = {
		xtype : "grid",
		id : "edit_grid",
		region : "south",
		columnWidth : 1,
		enableColumnMove : false,
		enableHdMenu : false,
		title : "数据模块输入信息",		
		autoExpandColumn : "in_name",
		autoExpandMin : 100,
		loadMask : true,
		height : 138,
		selModel : new Ext.grid.RowSelectionModel(),//设置为行选择器
		store : sub_store,
		columns : [
				new Ext.grid.RowNumberer({
					header : "序号",
					width : 35
				}),
				{
					dataIndex : "in_no",
					id : "in_no",
					header : "数据模块输入编号"					
				}, {
					dataIndex : "in_name",
					id:"in_name",
					header : "数据模块输入名称"
				}]
	};

	//上传个性化区域
	var p5 = {
		xtype : "grid",
		columnWidth : 1,
		enableColumnMove : false,
		enableHdMenu : false,
		title : "样张提示图",
		loadMask : true,
		height : 114,
		autoExpandColumn : "path",
		autoExpandMin : 100,
		selModel : new Ext.grid.RowSelectionModel(),//设置为行选择器
		store : image_store,
		columns : [
				new Ext.grid.RowNumberer({
					header : "序号",
					width : 35
				}),
				{
					dataIndex : "path",
					header : "文件名称",
					id : "path"
				},
				{
					xtype : "actioncolumn",
					header : "预览",
					width : 34,
					items : [ {
						icon : "images/shared/icons/fam/information.png", // Use a URL in the icon config
						tooltip : "预览",
						handler : function(grid, rowIndex, colIndex) {
							var rec = image_store.getAt(rowIndex);
							var win=Ext.getCmp("showimages");
							win.show();
							var html="<img id='imgpage' width="+win.getInnerWidth()+" height="+win.getInnerHeight()+" src='download.action?id="+encodeURI(rec.get('path'))+"'/>";
							win.update(html);
						}
					} ]
				} ]
	};

	//详细信息
	var p2 = {
		id : "p2",
	    labelWidth: 100,
		xtype: "form",
	    bodyStyle:"padding:5px 5px 0",
		defaultType: "textfield",
		autoScroll : true,
		items : [
				{
					id : "template.id",
					fieldLabel : "模板编号",
					anchor : "100%",
					disabled : true
				},
				{
					id : "template.name",
					fieldLabel : "模板名称",
					allowBlank : false,
					anchor : "100%",
					disabled : true
				},
				{
					id : "template.version",
					fieldLabel : "版本号",
					anchor : "100%",
					disabled : true
				},
				{
					id : "template.cardname",
					fieldLabel : "卡产品名称",
					anchor : "100%",
					disabled : true
				},
				{
					id : "template.type",
					fieldLabel : "账单类型",
					xtype : "billCombox",
					disabled : true,
					store : type_store
				}, {
					id : "template.state",
					fieldLabel : "状态",
					xtype : "billCombox",
					store : state_store,
					disabled : true
				}, {
					id : "template.storpath",
					fieldLabel : "模板存储路径",
					anchor : "100%",
					disabled : true
				}, {
					id : "template.jobpath",
					fieldLabel : "JOB文件存储路径",
					anchor : "100%",
					disabled : true
				}, p5, p4 ],
		buttonAlign : "center",
		buttons : [{
					text : "返回",
					handler : function() {
						Ext.getCmp("templ_panel").layout.setActiveItem(0);
					}
				} ],
		setParam : function(data) {
			Ext.getCmp("template.id").setValue(data.id);
			Ext.getCmp("template.name").setValue(data.name);
			Ext.getCmp("template.version").setValue(data.version);
			Ext.getCmp("template.cardname").setValue(data.cardname);
			Ext.getCmp("template.type").setValue(data.type);
			Ext.getCmp("template.storpath").setValue(data.storpath);
			Ext.getCmp("template.jobpath").setValue(data.jobpath);
			Ext.getCmp("template.state").setValue(data.state);
		}
	};
		
		var temp_pel = new Ext.Panel({
			border : false, 
			layout: "border",
			items : [ {
				id : "tempTree",
				xtype : "billTreePanel",
				dataUrl : "tree!product.action",
				autoScroll : true,
				root : new Ext.tree.AsyncTreeNode({
					id : "root",
					expanded : true
				}),
				listeners : {
					"click" : function(node) {
						if (node.isLeaf()) {
							Ext.getCmp("selcbut").setValue("");//清空查询条件
							Ext.getCmp("selcstatebut").setValue("");//清空查询条件
							Ext.getCmp("selcsnamebut").setValue("");//清空查询条件
							
							data_store.baseParams = {};
							data_store.baseParams["template.cardid"] = node.id;
							data_store.load({
								params : {
									start : 0,
									limit : limit
								}
							});
							Ext.getCmp("templ_panel").layout.setActiveItem(0);
						}
					}
				}
			}, {
				id : "templ_panel",
				region: "center",
				border : false, 
				layout:"card",
				activeItem:0,//显示第一个容器
				items : [ p1, p2 ]
			} ]
		});
	
	
	var CenterPanel=Ext.getCmp("CenterPanel");
	CenterPanel.removeAll();
	CenterPanel.add(temp_pel);
	CenterPanel.doLayout();
</script>